<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE HTML>
<html>
<head>
<title>My JSP 'registed-success.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link href="assets/ico/biologo.ico" rel="shortcut icon">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap-popover.js"></script>
<script type="text/javascript" src="js/bootstrap-scrollspy.js"></script>

<style type="text/css">
body {
	background-image: url("");
}

#container {
	margin-top: 60px;
	margin-left: 20%;
	margin-right: 20%;
}

form {
	font-size: 16px;
}

#myspan {
	text-align: right;
}
</style>
</head>

<body>
	<%@ include file="include/topbar.jsp"%>
	<div id="container">
		<form action="savesysuser.action">
			<div id="myspan"></div>
			<span style="color: red;font-size: 22px;">*</span>注册账号名称: <input maxlength="18"
				type="text" id="username" name="sysuser.username"
				onblur="verifyUsername()" onclick="verifyUsername1()" /><span
				style="display: none;color: red;" id="tishi1">该用户名已存在</span><span
				style="display: none;color: red;" id="tishi2">请输入用户名</span><br /> <span
				style="color: red;font-size: 22px;">*</span>账号密码：<input maxlength="18"
				type="password" name="sysuser.password" onblur="verifyOfPass1()"
				onclick="verifyOfPass2()" /> <span
				style="display: none;color: red;" id="tishi3">请输入密码</span><br /> <br />
			真实姓名：<input type="text" name="sysuser.realName" /><br /> 验证邮箱：<input maxlength="28"
				type="text" name="sysuser.clientEmail" />
				
				<input type="button" class="tranBtn"
				value="点击发送" /><span class="verifyEmailTishi"></span> <br /> 请输入得到的验证码：<br />
			<input type="text" name="clientNum" maxlength="18"/>
		</form>
		<input type="button" class="btn btn-success" value="注册" /> →→→→→
		现在去登陆页面→→→→→→→→→→→→<a href="app.action">登陆页面</a>

	</div>
	<hr />
	<div style="display:none;" class="alert alert-info">
		<strong>成功</strong>您注册的用户名及密码也成功，3秒后将跳转到登陆页面------
	</div>
</body>

<script type="text/javascript">
	function verifyUsername() {
		//alert($("[name='sysuser.username']").val());
		if ($("[name='sysuser.username']").val() == ""
				|| $("[name='sysuser.username']").val() == null) {
			//alert("cccccccc");
			$("#tishi2").show();
			return false;
		}
		$.post("verifyName.action", {
			"sysusername" : $("[name='sysuser.username']").val()
		}, function(data) {
			if (data == true) {
				$("#tishi1").show();
				return false;
			}
		});
	};
	function verifyUsername1() {
		$("#tishi1").hide();
		$("#tishi2").hide();
	}

	function verifyOfPass1() {
		if ($("[name='sysuser.password']").val() == ""
				|| $("[name='sysuser.password']").val() == null) {
			$("#tishi3").show();
			return false;
		}

	}
	function verifyOfPass2() {
		$("#tishi3").hide();
	}
	$(function() {
		$(".btn-success").click(function() {
			//alert($(".btn").val());
			verifyUsername();
			verifyOfPass1();
			if (($("[name='sysuser.username']").val() == "" || $(
					"[name='sysuser.username']").val() == null)
					|| ($("[name='sysuser.password']").val() == "" || $(
							"[name='sysuser.password']").val() == null)) {
				return false;
			} else {
				$.post("savesysuser.action",{"sysuser.username" : $("input[name='sysuser.username']").val(),
					"sysuser.password" : $("input[name='sysuser.password']").val(),
					"sysuser.realName" : $("input[name='sysuser.realName']").val(),
					"sysuser.clientEmail" : $("input[name='sysuser.clientEmail']").val(),
					"clientNum"	: $("input[name='clientNum']").val()
				},
					function(data) {
					if (data) {
						$(".alert-info").css("display","block");
						//var t = setTimeout("alert('5 seconds!')", 1000);
						setTimeout(function tiaozhuan() {
							window.location.href = "app.action";
						}, 3000);
					}else{
						alert("您输入的验证码有误，请核对后重新输入！");
					}
				});
			}
		});
	});
	
	$(function(){
		$("input[name='sysuser.clientEmail']").focus(function(){
			$(".verifyEmailTishi").text("");
		});
	});
	$(function() {
		$("input[class='tranBtn']").click(function() {
			alert($("input[name='sysuser.clientEmail']").val());
			if($("input[name='sysuser.clientEmail']").val()==""){
				$(".verifyEmailTishi").text("请输入您的邮箱");
				$(".verifyEmailTishi").css("color","red");
				return false;
			}else if(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/)
					.test($("input[name='sysuser.clientEmail']").val())){
				$(".verifyEmailTishi").text("请输入正确的邮箱！");
				return false;
			}
			$("input[class='tranBtn']").attr("value","发送中...");
			//alert($("input[name='eMail']").val());
			var e = $("input[name='sysuser.clientEmail']").val();
			$.post("verifyEmailForClient.action",{"emailClient":e},function(data){
				if(!data){
					alert("您输入的邮箱已经被注册，请更换邮箱！");
					$("input[class='tranBtn']").attr("value","点击发送");
					return false;
				}
				$.post("sendEmail.action",{"emailClient":e},
						function(data){
						if(data){
							return;
						}else {
							alert("服务器忙，请稍后");
							$("input[class='tranBtn']").attr("value","重新发送");
						}
					});
					return ;
			});
			//window.location.href = "sendEmail.action?emailClient=" + e;
		});
	});
</script>
</html>
